home *** CD-ROM | disk | FTP | other *** search
Text File | 1985-03-20 | 8.5 KB | 611 lines | [TEXT/MACA] |
-
-
- Wator Documentation
-
-
-
-
-
-
- ---------------------
-
-
-
-
-
-
-
- The program of Wator has been provided as an example of MACINTOSH
-
- programming. The development environment was AZTEC C, on a 128K MAC
- with
-
- an external drive. If you find this example valuable, I would appreciate a
-
- nominal contribution of $5 so that I can continue to provide programming
-
- examples of this kind.
-
-
-
-
- Send to:
-
-
-
-
- Robert Martin
-
-
-
-
- 2826 Lee Ave
-
-
-
-
- Waukegan, IL
-
-
-
-
-
-
- 60085
-
-
-
- Comments can be sent via EMAIL to 70156,240
-
-
-
-
-
- Wator
-
- -------
-
-
-
- The game of WATOR was invented by A. K. Dewdney. He wrote about it in
-
- the "COMPUTER RECREATIONS" column of the DEC '84 issue of "SCIENTIFIC
-
- AMERICAN". The world of wator is a toroidal planet, completely covered
-
- with water. For the purpose of this program, the surface of the torus has
-
- been unfolded, and is displayed as a rectangle.
-
-
-
- Wator has two types of inhabitants: sharks and fish. The fish have an
-
- unlimited food supply, breed happily. The sharks eat only fish, and will
-
- starve without food. Sharks also breed.
-
-
-
- Time passes on wator in increments called chronons. Each chronon, the
- fish
-
- and sharks move, eat, and breed.
-
-
-
- To start the game going, the user must decide on 5 critical values.
-
-
-
- % The initial
- number of fish
-
- % The initial
- number of sharks
-
- % The number of
- chronons it takes for a fish to breed.
-
- % The number of
- chronons it takes for a shark to breed.
-
- % The number of
- chronons it takes for a shark to starve.
-
-
-
- Once these values are set, there is nothing to do but watch as the sharks
-
- and fish arrange themselves into a neat little ecology. Sometimes the
-
- system becomes unstable, and all the fish get eaten. Of course then all
-
- the sharks die. Sometimes, there are too few fish to support all the
- sharks
-
- and the sharks all die, but the fish survive. Only the fish can win this
-
- game. The best the sharks can do is draw.
-
-
-
- Each fish and shark move in a random fashion, one space per chronon. If
-
- a shark can eat a fish in an adjacent space, it will do that rather than
-
- move to an empty square. The fish do not try to evade the sharks. When
-
- it comes time for a fish or a shark to breed, it must first move to an
- empty
-
- space, and then it leaves a fully mature offspring behind in the space it
-
- came from.
-
-
-
- Running the program
-
- ---------------------
-
-
-
- To start the game, double click the shark-and-fish icon of "wator". The
-
- opening sequence will run, and then a dialog box will be presented with
-
- the 5 values that you must specify. The default values represent a stable
-
- situation which is my favorite. Edit the values with mouse and keyboard,
-
- and push the "OK" button.
-
-
-
- The screen will fill with 3 windows. The most prominent, labelled "wator"
-
- is the rectangular representation of the unfolded torus of the planet of
-
- "Wator". In this window you will see black squares which are the sharks,
-
- and smaller grey squares which are the fish. As you watch they will dance
-
- around and multiply. The sharks will gobble down fish and array
- themsevles
-
- in fierce competition for feeding space.
-
-
-
- The second most prominent window is the population graph. This window
-
- displays two traces, the grey trace represents the fish population,
-
- the black trace represents the shark population. Each vertical division on
-
- the graph represents 200 individuals. Each horizontal division represents
-
- 50 chronons. A vertical separator bar divides the graph. To the left are
-
- the latest recordings, and to the right are the oldest. The separator moves
-
- from left to right, and then starts over again at the far left.
-
-
-
- The last window is labeled "statistics". It contains the current count of
-
- sharks and fish. It also contains the current time in chronons.
-
-
-
- Each of these windows may be dragged around with the mouse.
-
-
-
- To stop the game, select "Quit" from the "Wator" menu.
-
-
-
- Wator screens may be printed with the "caps-lock,shift,command-4"
- sequence.
-
- (see macintosh manual page 73).
-
-
-
-
-
- Wator Software
-
- ----------------
-
-
-
- Wator was written in C, using the AZTEC C compiler. I began writing it
-
- before I had recieved my copy of "INSIDE MACINTOSH", and so alot of the
-
- initial work was based on educated guessing. The initial version of Wator
-
- drew a rectangle on the screen, and manipulated the sharks and fish within
-
- it. The initial values were retrieved as command line parameters. Later I
-
- added the statistics rectangle, and still later I changed the two rectangles
-
- into windows.
-
-
-
- After I recieved "INSIDE MACINTOSH" I was able to add the opening
- sequence
-
- (which uses a method which is based on the "About File..." portion of
-
- the wonderful example program written by Cary Clark), the dialog box
-
- for parameters, the population graph and the event handling.
-
-
-
- Wator consists of 9 source files:
-
-
-
- % Wator.
- c The root module,
- contains the rules for operating the
-
-
-
-
- sharks and fish.
- Also contains the highest level code
-
-
-
-
- for controlling the
- ancillary functions such as event
-
-
-
-
- dectection, and
- window updates.
-
-
-
- % Watorut.
- c Wator Utilities. A
- set of utilities used almost
-
-
-
-
- exclusively by
- wator.c in order to draw the sharks and
-
-
-
-
- fish, and control
- some of the mathematical limitations
-
-
-
-
- of the torus.
-
-
-
-
-
-
- % Watevent.
- c Detects and
- handles mouseDown, keyDown, and Update
-
- events.
- Knows how to drag windows.
-
-
-
-
-
-
-
- % Watopen.
- c Contains the
- opening sequence. The animation in this
-
- program is
- quite intriguing, and a close examination
-
-
-
-
- should be a
- rewarding experience.
-
-
-
-
-
-
- % Watparm.
- c Puts up the dialog
- box to get the initial values. This
-
-
-
-
- module is most
- interesting for finding out how to put
-
-
-
-
- Icons into dialog
- boxes.
-
-
-
-
-
-
- % Watgraph.
- c Draws and
- maintains the population graph. This was
-
-
-
-
-
- probably the most
- chalenging module to write. There
-
-
-
-
-
- are several
- subtleties whithin Quickdraw which I found
-
-
-
-
-
- out about. This
- module is also about as large as
-
-
-
-
-
- the AZTEC C will
- support on a 128K MAC. As it is I
-
-
-
-
-
- had to compile it
- using {-Z200} to reduce the string
-
-
-
-
-
- space. A close
- examination of this routine will be
-
-
-
-
-
- very rewarding. It
- covers some animation techniques
-
-
-
-
-
- as well as
- techniques for drawing graphs, and updating
-
-
-
-
-
- windows.
-
-
-
- % Watmenu.
- c Controlls the menu
- bar, and the execution of menu commands.
-
-
-
- % Wator.
- h Contains all the
- global constants and data structures.
-
-
-
- % std.
- h
- My own standard
- header, which has my favorite conventions
-
-
-
-
- installed.
-
-
-
-
-
-
- Wator Resources
-
-
-
-
-
-
-
- -----------------
-
-
-
- I built all the resources with the first release of Apples Resource Editor
-
- which comes with the software supplement, and is also available from the
-
- MAUG. I kept the resources in a file named wator.res, and merged them
- into
-
- my linked code before running. I have not provided a copy of wator.res,
-
- since all the resources are available in the application itself. If you
-
- wish to do any development work on this program, I suggest that you first
-
- strip out the resources and then merge them back in when your changes
- have
-
- been made.
-
-
-
-
-
-
-
-
-
- Linking Wator
-
-
-
-
-
-
- ---------------
-
-
-
-
-
-
-
- I have provided a file named wator.lnk which contains the linking
-
- instructions for the linker. The command used to link the code after is
-
- is all compiled is: ln -f wator.lnk
-
-
-
- File Type
-
-
-
-
-
-
- -----------
-
-
-
-
-
-
-
-
- The Application is given the type type of: APPL WATX by the "Set File"
-
- utility that comes with the software supplement. The bundle bit is set
-
- at the same time.
-
-
-
- License
-
-
-
-
-
-
- ---------
-
-
-
-
-
-
-
-
- This program may be used by anyone. I don't care if you copy it a million
-
- times, or give it away to all your freinds and relatives. But please don't
-
- charge any money for it. Also, if you copy the source code, please copy
-
- this document with it.
-
-
-
- What about me?
-
-
-
-
-
-
-
- ----------------
-
-
-
-
-
-
-
-
- The game itself is yours. But if this write-up and the associated source
-
- code teach you something worth while, then I would appreciate a
-
- contribution of $5 to help me keep providing educational material like this.
-
-
-
- Send to
- : Robert Martin
-
-
-
-
- 2826 Lee Ave
-
-
-
-
- Waukegan, IL
-
-
-
-
-
- 60085
-
-
-
-